<template>
  <div>
    <el-card class="box-card" style="margin-top: 15px;width: 500px">
      <div v-for="o in 1" :key="o" class="text item">
        {{ '团队类型登记 ' }}
      </div>
    </el-card>
    <div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" style="margin-top: 15px">
        <el-form-item label="团队类型名称" prop="team_type" label-width="120px">
          <el-input v-model="form.team_type" style="width: 250px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit()">立即创建</el-button>
          <el-button @click="back()">返回</el-button>
        </el-form-item>
      </el-form>
    </div>



  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  data() {
    return {
      form: {
        team_type: '',
      },
      total: 0,
      params: {
        team_type:'',
        pageNum:1,
        pageSize:5
      },
      tableData: [],
      rules: {
        team_type: [
          { required: true, message: '请输入团队类型名称', trigger: 'blur' },
          { min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
        ],}
    };
  },
  created(){
    var team_typeid = this.$route.query.team_typeid
    request.get("http://localhost:9100/data_factory/team_details/type_finddetail/" + team_typeid).then(res =>{
      if (res.code === '0'){
        this.form = res.data[0];
      }else {

      }
    })
  },

  methods: {
    back(){
      this.$router.go(-1);
    },
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 如果表单验证通过，则发送请求
          request.post("http://localhost:9100/data_factory/team_details/type_add", this.form).then(res => {
            if (res.code === '0') {
              this.$message({
                message: '操作成功',
                type: 'success'
              });
            } else {
              this.$message({
                message: '操作失败',
                type: 'error'
              });
            }
          });
        } else {
          // 如果表单验证不通过，则显示错误信息，并且不发送请求
          this.$message({
            message: '请输入正确的团队负责人名称', // 或者其他适当的错误提示
            type: 'error'
          });
          return false; // 阻止表单提交
        }
      });
    }
  },
}
</script>